package cn.tedu.zhwy.cardealer.controller;

import cn.tedu.zhwy.base.response.JsonResult;
import cn.tedu.zhwy.cardealer.pojo.dto.VehicleQuery;
import cn.tedu.zhwy.cardealer.pojo.dto.VehicleSaveParam;
import cn.tedu.zhwy.cardealer.pojo.vo.VehicleVO;
import cn.tedu.zhwy.cardealer.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/vehicle")
@Slf4j
public class VehicleController {

    @Autowired
    VehicleService vehicleService;
    @GetMapping("select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery) {
        log.debug("查询车辆信息:vehicleQuery{}", vehicleQuery);
        List<VehicleVO> list = vehicleService.selectVehicle(vehicleQuery);
        log.debug("查询车辆信息:list{}", list);
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam){
        log.debug("新建车辆信息:vehicleSaveParam{}", vehicleSaveParam);
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("delete/{carId}")
    public JsonResult deleteVehicle(@PathVariable Long carId) {
        log.debug("删除车辆信息:carId{}", carId);
        vehicleService.deleteVehicle(carId);
        return JsonResult.ok();
    }
}
